package com.base.cn.platform.os.controller.course.cou.record;


import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.cou.record.CourseLearnFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 课程播放记录
 *
 * @author zjh
 * @since 2018-12-14
 **/

@RestController
@RequestMapping("/api/play/record")
public class ApiCourseLearnFlowController extends ApiBaseController {

    @Autowired
    CourseLearnFlowService  courseLearnFlowService;

    /**
     * 保存课程学习流水
     * @param userId
     * @param buyCourseId  套餐/课程ID（购买的课程ID）
     * @param courseId 课程ID
     * @param catalogId 目录ID
     * @param source 播放来源 1.WEB 2.H5 3.APP 4.小程序
     * @param  materialTypeKey 播放资源的类型 （LIVE，AUDIO，VIDEO，ARTICLE）
     * @param duration 播放时长（单位/秒）
     * @param finish 是否完成观看 1.未完成 2.已完成
     * @return
     */
    @RequestMapping("/savePlayRecordFlow")
    public Map<String, Object> savePlayRecordFlow(@RequestParam("userId") BigDecimal userId,
                                                  @RequestParam("buyCourseId") BigDecimal buyCourseId,
                                                  @RequestParam("courseId") BigDecimal courseId,
                                                  @RequestParam("catalogId") BigDecimal catalogId,
                                                  @RequestParam("source") int source,
                                                  @RequestParam("materialTypeKey") String materialTypeKey,
                                                  @RequestParam("duration") int duration,
                                                  @RequestParam(value = "finish",required =false,defaultValue = "1") int finish,
                                                  @RequestParam(value = "materialId",required = false)BigDecimal materialId) {
        Map<String, Object> playRecordFlow = new HashMap<>();
        playRecordFlow.put("userId", userId);
        playRecordFlow.put("buyCourseId", buyCourseId);
        playRecordFlow.put("courseId", courseId);
        playRecordFlow.put("catalogId", catalogId);
        playRecordFlow.put("source", source);
        playRecordFlow.put("duration", duration);
        playRecordFlow.put("materialTypeKey", materialTypeKey);
        playRecordFlow.put("materialId", materialId);
        return courseLearnFlowService.saveCourseLearnFlow(playRecordFlow,finish);
    }
}
